package com.yoomiito.app.present;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.home.HaoDanKuData;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.CouponGoodsActivity;
import com.yoomiito.app.utils.NetworkUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class CouponGoodsPresenter extends BaseActPresenter<CouponGoodsActivity> {
    public CouponGoodsPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getHaoDanku(String url,int sort,int hasCoupon,long page,String type){
        YmApi.getYmService()
                .getHaoDanKu("0",sort,hasCoupon,page,type,url)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<HaoDanKuData>(handleException()) {
                    @Override
                    public void onSuccess(HaoDanKuData danKuData) {
                        if (hasV()){
                            getV().dismissLoading();
                            getV().setData(danKuData);
                        }
                    }

                    @Override
                    public void onFail(ApiException error) {
                        if (hasV()){
                            getV().dismissLoading();
                        }
                    }
                });
    }
}
